package com.springboot.study.aspjectj;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: guodong
 * @Date: 2021/12/17 11:34
 * @Version: 1.0
 * @Description:
 */
@Aspect
@Component
public class LogPrintAspect{

    //自定义切点位置
    //把切面连接点放在我们注解上
    @Pointcut("@annotation(com.springboot.study.aspjectj.LogPrint)")
    private void controllerAspect(){}


    //自定义前置切面
    //访问controller方法前先执行的方法
    @Before("controllerAspect()")
    public void printLog(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.ms");
        System.out.println(sdf.format(new Date())+" || ");
    }
}